const { AccessKeyID, AccessKeySecret } = require('../config/config.default')
const RPCClient = require('@alicloud/pop-core').RPCClient

// 初始化
function initVodClient(accessKeyId, accessKeySecret) {
  const regionId = 'cn-shanghai' // 点播服务接入地域
  const client = new RPCClient({
    //填入AccessKey信息
    accessKeyId,
    accessKeySecret,
    endpoint: `http://vod.${regionId}.aliyuncs.com`,
    apiVersion: '2017-03-21',
  })

  return client
}

// 获取vod凭证
exports.getVod = async (req, res) => {
  const client = initVodClient(AccessKeyID, AccessKeySecret)
  const vodBack = await client.request(
    'CreateUploadVideo',
    {
      Title: 'this is a sample',
      FileName: 'filename.mp4',
    },
    {}
  )
  res.status(200).json({ vod: vodBack })
}
